package authority

import (
	"cgs-server/helper"
	"cgs-server/server"
	"cgs-server/server/model"
	"net/http"
)

func init() {
	//server.Handle(http.MethodGet, "/api/OperatingAuthority/Get", Get, server.Administrator)
	server.Get("/api/Authority/Get", GetAuthority, "获取权限列表", server.ManageBackend)
	server.Get("/api/Authority/GetAppAuth", GetAppAuthority, "获取应用权限列表", server.Login)
}

func GetAuthority(w http.ResponseWriter, r *http.Request) {
	authorityService := NewAuthorityService()
	result, err := authorityService.List(&model.DataUserModel{})
	if err != nil {
		_, _ = helper.WriteJSON(w, server.Fail(err.Error()))
	}

	_, _ = helper.WriteJSON(w, server.OK().WithData(result))

}

func GetAppAuthority(w http.ResponseWriter, r *http.Request) {
	authorityService := NewAuthorityService()
	result, err := authorityService.ListAppAuth()
	if err != nil {
		_, _ = helper.WriteJSON(w, server.Fail(err.Error()))
	}

	_, _ = helper.WriteJSON(w, server.OK().WithData(result))
}
